package cn.com.css.taxInspection.common.config;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.common.exception.BusinessException;
import cn.com.css.taxInspection.system.mapper.GeneratorMapper;
import cn.com.css.taxInspection.system.mapper.SysGeneratorMysqlMapper;
import cn.com.css.taxInspection.system.mapper.SysGeneratorOracleMapper;
import cn.com.css.taxInspection.system.mapper.SysGeneratorSqlServerMapper;


/**
 * 数据库配置
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Configuration
public class DbConfig {

	@Value("${project.database}")
	private String database;
	@Resource
	private SysGeneratorMysqlMapper sysGeneratorMysqlMapper;
	@Resource
	private SysGeneratorOracleMapper sysGeneratorOracleMapper;
	@Resource
	private SysGeneratorSqlServerMapper sysGeneratorSqlServerMapper;

	@Bean
	@Primary
	public GeneratorMapper getGeneratorMapper() throws BusinessException {
		if (Constants.DB_TYPE_MYSQL.equalsIgnoreCase(database)) {
			return sysGeneratorMysqlMapper;
		} else if (Constants.DB_TYPE_ORACLE.equalsIgnoreCase(database)) {
			return sysGeneratorOracleMapper;
		} else if (Constants.DB_TYPE_SQL_SERVER.equalsIgnoreCase(database)) {
			return sysGeneratorSqlServerMapper;
		} else {
			throw new BusinessException("不支持当前数据库：" + database);
		}
	}
}
